package com.ruoyi.profession.service.impl;

import com.ruoyi.profession.domain.Statistics;
import com.ruoyi.profession.mapper.StatisticsMapper;
import com.ruoyi.profession.service.StatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.sl.draw.binding.CTEmbeddedWAVAudioFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class StatisticsServiceImpl implements StatisticsService {
    @Autowired
    private StatisticsMapper statisticsMapper;

    @Override
    public Statistics fetchStatistics() {
        LocalDate now = LocalDate.now();

        // 调用Repository方法获取数据
        List<Integer> intervalAge=new ArrayList<>();
        Integer twe= statisticsMapper.findAgeTwe(now);//20以下
        intervalAge.add(twe);
        Integer three= statisticsMapper.findAgeThree(now);//30到20
        intervalAge.add(three);
        Integer four= statisticsMapper.findAgeFour(now);//40到30
        intervalAge.add( four);
        Integer five= statisticsMapper.findAgeFive(now);//50到40
        intervalAge.add(five);
        Integer six= statisticsMapper.findAgeSix(now);//50以上
        intervalAge.add(six);


        List<Integer> people = statisticsMapper.findPeopleCounts();


        //0-9;10-19;20-29;30之上;
        HashMap<LocalDate,Integer> joinWork = new HashMap<>();
        LocalDate now1=now.minusYears(10);
        Integer joinWork1=statisticsMapper.findJoinWorkYear1(now);
        joinWork.put(now1,joinWork1);
        LocalDate now2=now.minusYears(20);
        Integer joinWork2=statisticsMapper.findJoinWorkYear2(now);
        joinWork.put(now2,joinWork2);
        Integer joinWork3=statisticsMapper.findJoinWorkYear3(now);
        LocalDate now3=now.minusYears(30);
        joinWork.put(now3,joinWork3);

        Integer certificate = statisticsMapper.findCertificate();
//        List<Integer> entering = statisticsMapper.findEnteringCounts();

        // 封装结果到Statistics对象中
        Statistics statistics = new Statistics();
        statistics.setIntervalAge(intervalAge);
        statistics.setPeople(people);
        statistics.setJoinWork(joinWork);
        statistics.setCertuficate(certificate);
//        statistics.setEntering(entering);

        return statistics;
    }
}
